package servlet;

import http.LmyRequest;
import http.LmyResponse;

public abstract class LmyHttpServlet implements LmyServlet {

    @Override
    public void service(LmyRequest request, LmyResponse response){

        try {
            if ("GET".equalsIgnoreCase(request.getMethod())) {
                this.doGet(request, response);
            } else if ("POST".equalsIgnoreCase(request.getMethod())) {
                this.doPost(request, response);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //使用抽象模板设计模式
    //让LmyHttpServlet 子类 LmyServlet实现
    public abstract void doGet(LmyRequest request, LmyResponse response) throws Exception;

    public abstract void doPost(LmyRequest request, LmyResponse response) throws Exception;
}
